<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" >
<head>
    <meta charset="utf-8">
    <title>药品信息编辑</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <script src="/js/jquery.js"></script>
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<form class="layui-form" action="" method="">

    <input type="hidden" name="oid" th:value="${medicine.medicineId}" class="layui-input">

    <div class="layui-form-item">
        <label class="layui-form-label required">药品编号</label>
        <div class="layui-input-block">
            <input type="number" name="medicineId" lay-verify="required" lay-reqtext="药品编号不能为空" th:value="${medicine.medicineId}" class="layui-input">
            <tip>注意，药品编号唯一，请保证填写正确。</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">药品类别</label>
        <div class="layui-input-block">
            <input type="radio" name="category" value="外用药品" title="外用药品" checked="">
            <input type="radio" name="category" value="口服药品" title="口服药品">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">药品名称</label>
        <div class="layui-input-block">
                <input type="text" name="name" lay-verify="required" lay-reqtext="药品名称不能为空"  th:value="${medicine.name}" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">库存数量</label>
        <div class="layui-input-block">
                <input type="number" name="number" th:value="${medicine.number}" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">单价</label>
        <div class="layui-input-block">
                <input type="number" name="price" th:value="${medicine.price}" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</form>
<script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    //JavaScript代码区域
    layui.use('element', function () {
        var element = layui.element;
    });
    layui.use(['form'], function () {
        var form = layui.form;
        form.on('submit(saveBtn)', function (data) {
            $.ajax({
                url: "/backstage/medicine/toUpdate",
                type: "post",
                dataType: "json",
                data: {
                    'oid': data.field.oid,
                    'medicineId': data.field.medicineId,
                    'category': data.field.category,
                    'name': data.field.name,
                    'number': data.field.number,
                    'price': data.field.price
                },
                success: function (res) {
                    var json = JSON.parse(res);
                    layer.close(index);
                    if (json.result == "1") {
                        layer.msg("编辑成功！", {icon: 6});
                        parent.a();
                    } else {
                        layer.msg("编辑失败！", {icon: 5});
                    }
                }
            });
        });
        return false;
    });
</script>
</body>
</html>